package com.software.lineragent.dao;

import java.security.NoSuchAlgorithmException;

public class LinerAgentTransaction {

	private LinerAgentDao linerAgentDao;
	

	public LinerAgentDao getLinerAgentDao() {
		return linerAgentDao;
	}

	public void setLinerAgentDao(LinerAgentDao linerAgentDao) {
		this.linerAgentDao = linerAgentDao;
	}

	public boolean login(String email,String password){
		LinerAgent linerAgent = new LinerAgent();
		linerAgent.setEmail(email);
		linerAgent.setPassword(password);
		LinerAgent la = linerAgentDao.queryLinerAgent(linerAgent);
		if(la != null){
			if(password.equals(la.getPassword())){
				return true;
			}
		}
		return false;
	}
	
	/**
	 * 
	 * 前提：判断账户是否已经被注册
	 * @param username
	 * @param password
	 * @param email
	 * @param description
	 * @param phone
	 * @return
	 * @throws NoSuchAlgorithmException
	 */
	public boolean register(String name,String password, String email,String phone,String description){
		LinerAgent linerAgent = new LinerAgent();
		linerAgent.setEmail(email);
		linerAgent.setPassword(password);
		linerAgent.setPhone(phone);
		linerAgent.setName(name);
		linerAgent.setDescription(description);
		
		LinerAgent la = linerAgentDao.queryLinerAgent(linerAgent);
		if(la != null){
			return false;
		}
		try{
			linerAgentDao.addLinerAgent(linerAgent);
			return true;
		}catch(Exception e){
			return false;
		}	
	}
}
